The combine() operator for Flow combines the most recent emission from two flows, after either emits a new value. Those values are combined by means of the lambda expression or other function type supplied to combine(). This continues until both upstream flows are completed.

In this case, we have a flow of capital letters, each with a 100 millisecond delay after each emission. We also have a flow of lowercase letters, each with a 133 millisecond delay after each emission. We combine() those two flows, mapping the two letters into a Pair using the to operator.

The capital-letter flow will complete before the lowercase-letter flow will, as we have more lowercase letters and a longer delay. Yet, combine() will emit the combinations until both flows are completed. At the time either upstream flow emits a value, combine() takes the latest value from each flow, combines them (in this case into a Pair), and emits the result.

You can learn more about this in:
Tags:
Run Edit